<html>
<!-- =====================================================================

  File:      VisualStudio_Project_Notes.htm for Adventure Works Cycles Storefront Sample
  Summary:   Self-documentation for application
  Date:	     June 16, 2003

=====================================================================

  This file is part of the Microsoft SQL Server Code Samples.
  Copyright (C) Microsoft Corporation.  All rights reserved.

This source code is intended only as a supplement to Microsoft
Development Tools and/or on-line documentation.  See these other
materials for detailed information regarding Microsoft code samples.

THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.

======================================================= -->
    <head>
        <title>Adventure Works Cycles Storefront Documentation</title>
        <link rel="stylesheet" href="style.css">
    </head>
    <body leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0" marginheight="0" marginwidth="0">
        <table cellpadding="10" cellspacing="0" border="0">
            <tr>
                <td colspan="2" class="HeadBg">
                    <span class="Title">Adventure Works Cycles Storefront Documentation</span>
                </td>
            </tr>
            <tr>
                <td rowspan="10">
                    &nbsp;
                </td>
                <td class="Normal" width="98%">
                    <h1>
                        Visual Studio Project Notes&nbsp;(C#)
                    </h1>
                    <P>
                        This version of the Adventure Works Cycles Storefront application 
                        has been packaged as a Microsoft&reg; Visual Studio&reg; .NET application, specifically a Visual C# 
                        .NET "ASP.NET Web Application" project.&nbsp; In addition to showing the 
                        Adventure Works Cycles Storefront application, this sample shows how to implement a real web 
                        application in VS.NET using Microsoft SQL Server&trade; 2005 as the database backend.
                    </P>
                    <P>
                        <STRONG>Code-Behind</STRONG>.&nbsp; One of the big benefits of ASP.NET is a 
                        much more complete separation between static content (HTML, text and tags) from 
                        code.&nbsp; This sample uses ASP.NET's 
                        code-behind model for separating code from content.&nbsp; This way, the 
                        page&nbsp;code is a fully encapsulated class which gets the full benefits of 
                        code editing in VS.NET: syntax color coding, statement completion, 
                        auto-insertion of event handling methods, design-time syntax checking and full 
                        debugging support.                       
                    </P>
                    <UL>
                        <LI>
                            <FONT style="BACKGROUND-COLOR: #ffffff"><STRONG>Note</STRONG>: It is possible to 
                                create, edit and debug single-file ASPX files in VS.NET, however most of the 
                                features listed above are not supported for <EM>code</EM> within a single-file 
                                ASPX file.&nbsp; To create a single file ASPX, select Project &gt; Add New 
                                Item, and create a new Text file with the .ASPX extension.&nbsp; </FONT>
                        </LI>
                    </UL>
                    <P>
                        When you create a new ASP.NET page, or "Web Form," VS.NET creates both the 
                        .ASPX file, and the code-behind file.&nbsp; By default the code-behind file is 
                        hidden, but you can see it by selecting Project &gt; <b>Show All Files</b>.
                    </P>
                    <P>
                        To work with a Web Form in VS.NET, double-click the file name in Solution 
                        Explorer, or right-click and select one of the available actions.&nbsp; <STRONG>Open</STRONG>
                        will open&nbsp;an ASPX file in design view, and a .CS file in code view.&nbsp; <STRONG>
                            Open With</STRONG> permits you to select a different editor for the file, 
                        for example, Notepad.&nbsp; <STRONG>View Code</STRONG> always opens the 
                        code-behind for the selected file (even when the ASPX file is selected).&nbsp; 
                        Likewise, <STRONG>View Designer </STRONG>always opens the ASPX file.
                    </P>
                    <P>
                        &nbsp;<IMG src="images/code-behind.gif" align="top" width="192" height="57"><IMG src="images/designerverbs.gif" align="top" width="237" height="129">
                    </P>
                    <P>
                        The Web Forms designer also uses the &lt;%@ Page %&gt; directive (or &lt;%@ 
                        Control %&gt; directive for user controls) to associate the two files.&nbsp; 
                        Minimally, code-behind ASP.NET pages and user controls created in VS.NET need 
                        the following attributes:
                    </P>
                    <PRE>        
    &lt;%@ Page Language="c#" AutoEventWireup="false" Codebehind="WebForm1.aspx.cs" Inherits="PortalVS.WebForm1"%&gt;
    
    &lt;%@ Control Language="c#" AutoEventWireup="false" Codebehind="myControl.ascx.cs" Inherits="PortalVS.myControl"%&gt;
        </PRE>
                    <UL>
                        <LI>
                            <U>AutoEventWireup</U>.&nbsp; This should be false for VS.NET code-behind 
                        pages and user controls.&nbsp; Setting AutoEventWireup to false disables the 
                        automatic Page wireup of page events when a specially named method is found in 
                        the code (for example, Page_Load).&nbsp; VS.NET always creates the page event 
                        wireup explicitly in code.&nbsp;
                        <LI>
                            <U>Codebehind</U>.&nbsp; This is a design-time only attribute used by the 
                        Web Forms designer.&nbsp;
                        <LI>
                            <U>Inherits</U>.&nbsp; This is used at runtime to associate the code in the 
                            code-behind class with the code generated from the ASPX file.
                        </LI>
                    </UL>
                    <P>
                        <STRONG>Project Properties</STRONG>.&nbsp; In a Visual C# application, the .NET 
                        namespace for the code in the project is&nbsp;provided by the Project 
                        Properties, as is the name of the assembly to build.&nbsp; In this project, the 
                        assembly name is set to "Portal."&nbsp; The Default namespace is not set, which 
                        permits the developer to choose the namespace explicitly on a per-file basis. 
                        &nbsp; To see this, examine Project &gt; Properties.&nbsp;
                    </P>
                    <P>
                        Another interesting feature of Project Properties is the ability to specific 
                        Imports statements at the project level.&nbsp; This reduces the code in each 
                        code file by several lines.
                    </P>
                    <P>
                        <STRONG>Compiling and Running the Application</STRONG>.&nbsp; Changes to the 
                        code-behind class must be compiled prior to running the page.&nbsp; You can 
                        compile using the Build &gt; Build command.
                    </P>
                    <UL>
                        <LI>
                            <STRONG>Tip</STRONG>:&nbsp; The Ctrl-F8 keyboard shortcut (<STRONG>Build and Browse</STRONG>) 
                            will both compile the project and launch the selected page in the browser.</LI>
                    </UL>
                    <P>
                        To browse the application in a browser, right-click the Default.aspx file, and 
                        select one of the Browse options.&nbsp; <STRONG>View in Browser</STRONG> (Alt-V) 
                        will open the page in the default browser within VS.NET.&nbsp; <STRONG>Browse 
                            With...</STRONG> lets you select an external browser, and even set&nbsp;it 
                        as your "View in Browser" default.&nbsp;
                    </P>
                    <P>
                        To launch the application in the debugger,&nbsp;first set your 
                        breakpoints.&nbsp; Then right click an appropriate page and select Set As Start 
                        Page.&nbsp; Then you can press F5 to launch the debugger.
                    </P>
            </tr>
        </table>
    </body>
</html>
